--https://www.lua.org/pil/11.4.html

local Q = Class{
_name = "Queue",
init = function (self )

end
}


Q.first, Q.last = 0, -1

lume.extend(Q, {
	    push_left = function (self , v)
local first = self.first - 1
		  self.first = first
		  self[first] = v
end,

	    push_right = function (self , v)
local last = self.last + 1
		  self.last = last
		  self[last] = v
end,

	    pop_left = function (self )
local first = self.first
		  if not (first <= self.last) then  error("Assertion failed: first <= self.last")  end
		  local value = self[first]
		  self[first] = nil
		  self.first = first + 1
		  return value
end,

	    pop_right = function (self )
local last = self.last
		  if not (last >= self.first) then  error("Assertion failed: last >= self.first")  end
		  local value = self[last]
		  self[last] = nil
		  self.last = last - 1
		  return value
end
	    
	})

return Q
